package com.jingdong.service.impl;

import com.jingdong.dao.UserDao;
import com.jingdong.dao.impl.UserDaoImpl;
import com.jingdong.enity.User;
import com.jingdong.service.UserService;

import java.util.List;

public class UserServiceImpl implements UserService {
    private UserDao userDao = new UserDaoImpl();
    public boolean register(User user) throws Exception{
        //进行注册的操作
        //如果账户已经存在 就返回注册失败

        boolean flag = userDao.findUserByUsername(user.getUsername());
        if(!flag){
            //如果账户不存在 就进行注册
            int i = userDao.register(user);
            return i > 0 ? true : false;
        }else{
            return false;
        }
    }

    //查找所有用户信息
    public List<User> findAll() throws Exception {
        return userDao.findAll();
    }

    //登录的功能
    public boolean login(User user) throws Exception{


        boolean flag = userDao.login(user.getUsername(), user.getPassword());
        return flag ? true : false;
    }
}
